/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.sisrest.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.edu.upc.dew.sisrest.dao.LocalDao;
import pe.edu.upc.dew.sisrest.model.Local;

/**
 *
 * @author Aldo
 */
@Repository
public class LocalDaoHibernate extends HibernateDaoSupport implements LocalDao {

    @Autowired
    public LocalDaoHibernate(SessionFactory sessionFactory){
        setSessionFactory(sessionFactory);
    }

    @Override
    public List<Local> obtenerLocales() {
        List lista = getHibernateTemplate().find(" from Local ");
        return lista;
    }

    @Override
    public Local obtenerLocal(String sId) {
        return (Local) getHibernateTemplate().get(Local.class, sId);
    }

    @Override
    public void grabarLocal(Local objLocal) {
        getHibernateTemplate().saveOrUpdate(objLocal);
    }

    @Override
    public void eliminarLocal(String sId) {
        Local oLocal = obtenerLocal(sId);
        getHibernateTemplate().delete(oLocal);
    }

}
